package com.heima.leetcode.datastructure.binarysearchtree;

import com.heima.leetcode.datastructure.binarytree.LevelOrderTraversal;

import java.util.LinkedList;
import java.util.function.Consumer;

/**
 * @author 勾新杰
 * @version 1.0
 * @date 2024/9/8 10:53
 */
public class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    public TreeNode(int val) {
        this.val = val;
    }

    public TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }

    public boolean isSameTree(TreeNode tree2){
        TreeNode tree1 = this;
        return isSameTree(tree1, tree2);
    }

    private boolean isSameTree(TreeNode tree1, TreeNode tree2){
        if (tree1 == null && tree2 == null){
            return true;
        }else if (tree1 == null || tree2 == null){
            return false;
        }else {
            if (tree1.val == tree2.val){
                return isSameTree(tree1.left, tree2.left) && isSameTree(tree1.right, tree2.right);
            }
            return false;
        }
    }
}
